from threading import Thread
import logging
from logic.convert import Process

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# 创建 handler 输出到文件
file_handler = logging.FileHandler("运行日志.log", mode='a') # 一定要加上 mode='w'
file_handler.setLevel(logging.INFO)

# handler 输出到控制台
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)

# 创建 logging format
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)

# add the handlers to the logger
logger.addHandler(file_handler)
logger.addHandler(console_handler)

from threading import Thread, Event

class Work(Thread):
    def __init__(self,file_path, save_file_name):
        super(Work, self).__init__()
        self._finished = Event()

        self.file_path = file_path
        self.save_file = save_file_name

        self.ep = Process(self.file_path,self.save_file)


    def run(self):
        logger.info('开始处理：' + self.file_path)

        try:
            self.ep.p() # 替换成真正的函数
        except:
            logger.error('处理失败！')

        self._finished.set()

    def is_finished(self):
        return self._finished.is_set()